package com.ysd.lis.controller.lab;

import com.ysd.common.Result;
import com.ysd.lis.annotation.LogDetail;
import com.ysd.lis.aspect.OperationType;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.dto.UploadCipherText;
import com.ysd.lis.request.AddInstrSetupParam;
import com.ysd.lis.request.DeleteParam;
import com.ysd.lis.request.InstrSetupPageParam;
import com.ysd.lis.service.lab.LabInstrSetupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author bai
 * @since 2023-12-09
 */
@Api(tags = "仪器管理")
@RestController
@RequestMapping("/lis/instrSetup")
public class LabInstrSetupController extends BaseController {

    @Autowired
    private LabInstrSetupService labInstrSetupService;

    @ApiOperation("获取仪器")
    @GetMapping("/findInstrSetupList")
    public Result findInstrSetupList(InstrSetupPageParam instrSetupPageParam) {
        return labInstrSetupService.findLabInstrSetup(instrSetupPageParam);
    }

    @ApiOperation("获取仪器")
    @GetMapping("/getInstrSetupList")
    public Result getInstrSetupList(InstrSetupPageParam instrSetupPageParam) {
        return labInstrSetupService.getInstrSetupList(instrSetupPageParam);
    }

    @ApiOperation("获取所有仪器")
    @GetMapping("/findLabInstrSetupList")
    public Result findInstrSetupList(@RequestParam(value = "rptGroupId", required = false) String rptGroupId) {
        return labInstrSetupService.findLabInstrSetupList(rptGroupId);
    }
    @ApiOperation("根据报告单元获取仪器和通道号")
    @GetMapping("/findInstrSetupAndChannelList")
    public Result findInstrSetupAndChannelList(@RequestParam(value = "rptGroupId", required = false) String rptGroupId,
                                               @RequestParam(value = "itemNo", required = false) String itemNo
                                               ) {
        return labInstrSetupService.findInstrSetupAndChannelList(rptGroupId,itemNo);
    }

    @ApiOperation("添加仪器")
    @PostMapping("/addInstrSetup")
    @LogDetail(requestParam = "addInstrSetup", operationType = OperationType.INSERT, module = "检验仪器", content = "增加【instrName】检验仪器", businessName = "instrName")
    public Result addInstrSetup(@RequestBody AddInstrSetupParam addInstrSetupParam) {
        return labInstrSetupService.addLabInstrSetup(addInstrSetupParam);
    }

    @ApiOperation("编辑仪器")
    @PostMapping("/edit")
    @LogDetail(requestParam = "edit", operationType = OperationType.UPDATE, module = "检验仪器", content = "编辑【instrName】检验仪器", businessName = "instrName")
    public Result editInstrSetup(@RequestBody AddInstrSetupParam addInstrSetupParam) {
        return labInstrSetupService.editLabInstrSetup(addInstrSetupParam);
    }

    @ApiOperation("根据id删除仪器")
    @PostMapping("/deleteInstrSetup")
    @LogDetail(requestParam = "deleteInstrSetup", operationType = OperationType.DELETE, module = "检验仪器", content = "删除【names】检验仪器", businessName = "names")
    public Result deleteInstrSetup(@RequestBody DeleteParam deleteParam) {
        return labInstrSetupService.deleteLabInstrSetup(deleteParam);
    }

    @ApiOperation("同步仪器")
    @GetMapping("/syncInstrs")
    public Result syncInstrs() {
        return labInstrSetupService.syncInstrs();
    }


    @ApiOperation("查看仪器日志表")
    @GetMapping("/findStaInsterLogList")
    public Result findStaInsterLogList(){
        return labInstrSetupService.findStaInsterLogList();
    }

    /***
     * 上传注册码
     *
     */
    @ApiOperation("上传检测标准附件")
    @PostMapping("/uploadRegisterFile")
    public Result uploadRegisterFile(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request) throws Exception {
        return  labInstrSetupService.uploadRegisterFile(file,request);
    }

    @ApiOperation("上传密文")
    @PostMapping("/uploadRegisterCipherText")
    public Result uploadRegisterCipherText(@RequestBody UploadCipherText uploadCipherText) throws Exception {
        return  labInstrSetupService.uploadRegisterCipherText(uploadCipherText);
    }
}
